const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        index: path.resolve(__dirname, './src/index.tsx'),
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].[contenthash].bundle.js',
        publicPath: './'
    },
    module: {
        rules: [
            {
                test: /.(ts|tsx)$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /.(scss|css)$/,
                include: [/(.)*antd.css/, path.resolve(__dirname, 'src')],
                use: [
                    // Creates `style` nodes from JS strings
                    "style-loader",
                    // Translates CSS into CommonJS
                    "css-loader",
                    // Compiles Sass to CSS
                    "sass-loader",
                ],
            },
            {
                test: /\.(png|jpg|gif|jpeg)$/,
                exclude: /node_modules/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 8196
                    }
                }]
            },
            {
                test: /\.(woff|woff2|ttf|eot|svg|mp3)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'file-loader?name=assets/[name].[hash:8].[ext]',
                    },
                ],
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: path.resolve(__dirname, './public/index.html'),
        }),
    ],
    resolve: {
        extensions: ['.js', '.ts', '.jsx', '.tsx']
    },
    resolveLoader: {
        modules: [
            path.resolve(__dirname, "node_modules"),
            path.resolve(__dirname, "../", "node_modules"),
            path.resolve(__dirname, "./src/loaders")
        ],
    }
};